package Main;

import java.util.ArrayList;

public class Event {
	
	public enum EventStatus{
		open,
		closed
	};
	
	private static int lastEventID=0;
	private int eventID;
	public String eventTitle;
	public String eventDate;
	public String eventTime;
	public int hID;
	public int eventCapacity;	
	public int remainningCapacity;
	public EventStatus eventStatus;
	public ArrayList<Booking> bookings;
	
	private int getID()
	{
		return lastEventID++;
	}
	
	public Event(String title, String date, String time,int id, int capacity)
	{
		eventID=getID();
		eventTitle=title;
		eventDate=date;
		eventTime=time;
		hID=id;
		remainningCapacity=capacity;
		eventCapacity=capacity;
		bookings=new ArrayList<Booking>();
		eventStatus=EventStatus.open;
	}
	
	public synchronized void book(String fName, String lName, int numberOfSeats)
	{
		if(eventStatus==EventStatus.open)
		{
			if(numberOfSeats <= remainningCapacity)
			{
				for( int i = 0; i< numberOfSeats; i++)
				{
					Booking b = new Booking(fName,lName);
					bookings.add(b);
				}
				System.out.println("Booking was done for :" +fName+" "+lName+ " for " + numberOfSeats + " seats");
				remainningCapacity-=numberOfSeats;
			}
			else
			{
				System.out.println("Event cannot accomodate requested seats: " + fName + " " + lName );
			}
			
			
		}
		else
		{
			System.out.println("Event is not open: " + fName + " " + lName );
		}
		
	}
	
	public String toString()
	{
		String str="";
		str= "ID: "+ eventID + "\n"
				+ "EventTitle: " + eventTitle + "\n"
				+ "EventDate: " + eventDate + "\n"
				+ "Hall: " + hID + "\n"
				+ "EventCapaciry: " + eventCapacity + "\n"
				+ "EventStatus: " + eventStatus + "\n";
		return str;
	}

}
